$(function () {
	uForms = $('.UploadForm');
	jQuery.each(uForms, function() {
		var id = $(this).attr('id');
		if (!id) return;
		var up = new FancyUpload('#'+ id + ' .upload .upload-status', '#'+ id + ' .upload .upload-list', {
			target: '#'+ id + ' .upload .upload-browse',		// flashを設置する位置を指定
			verbose: true,					// 詳細ログの表示フラグ
			multiple: true,					// ファイル複数選択スイッチ
			path: './vars/mod/upload/src/Swiff.Uploader.swf',

			fallback: '#'+ id + ' .upload-fallback',	// フォールバックの指定（flashが使えない時のフォーム）

			url: null,
			method: null,
			data: null,
			mergeData: null,
			fieldName: null,

			// コールバック関数の登録
			Callbacks: {
				onload: function () {
					var upload = this;

					$('#'+ id + ' .upload .upload-clear').click (function (e) {
						upload.instance.remove();
						$(upload.list + ' .file').each (function() { $(this).fadeOut("fast"); });
						e.preventDefault();
					});

					$('#'+ id + ' .upload .upload-clear').click (function (e) {
						upload.instance.start();
						e.preventDefault();
					});

					$('#'+ id + ' .upload .file-remove').live ('click', function (e) {
						var thislist = $(this).parents('li');
						var id = $(upload.list + ' .file').index(thislist);
						upload.instance.fileRemove(id + 1);
						thislist.fadeOut ("fast");
						e.preventDefault();
					});
				},

				onselect: function (args) {
					this.setPosition();
					var Files = args[0];
					var failFiles = args[1];
					var Queue = args[2];

					var upload = this;

					for (var File in Files) {
						build = '<li class="file">';
						build += '<span class="file-size">' + Files[File].size + 'B</span>';
						build += '<a class="file-remove" href="#" title="Click to remove this entry.">Remove</a>';
						build += '<span class="file-name">'+ Files[File].name + '</span>';
						build += '<span class="file-info"></span>';
						build += '</li>';
						var list = $(upload.list);
						if (list) {
							list.append (build);
						}
					}
				},

				onstart: function () {
				},

				onfileStart: function (args) {
				},

				onfileComplete: function (args) {
				}

			}
		});
	});
});
